import Vue from 'vue'
import Vuex from 'vuex'
import meituan from "./meituan.js"
import VuexPersist from 'vuex-persist'
// import createPersistedState from 'vuex-persistedstate'
Vue.use(Vuex)
const vuexLocal = new VuexPersist({
  storage: window.localStorage //可选，sessionStorage/indexDB
});
export default new Vuex.Store({
  // plugins: [createPersistedState()],
  state: {
    vuexn: "hello",
    arr: [{
        title: "【5本26.8元】经典儿童文学彩图青少版八十天环游地球中学生语文教学大纲",
        price: "12.60",
        n: 1,
        pricez: 12.60,
        checked: false
      },
      {
        title: "【5本26.8元】经典儿童文学彩图青少版八十天环游地球中学生语文教学大纲",
        price: "24.80",
        n: 1,
        pricez: 24.80,
        checked: false
      },
      {
        title: "【5本26.8元】经典儿童文学彩图青少版八十天环游地球中学生语文教学大纲",
        price: "29.80",
        n: 1,
        pricez: 29.80,
        checked: false
      },
    ],
    he: 0,
    value: "",
    value1: "",
    arrNew: [],
    n: 0,
    arrNew1: []

  },
  mutations: {
    // jia(state, index) {
    //   state.arr[index].n++
    //   state.arr[index].pricez = state.arr[index].price * state.arr[index].n
    // },
    // jian(state, index) {
    //   state.arr[index].n--
    //   state.arr[index].pricez * state.arr[index].n
    //   state.arr[index].pricez = state.arr[index].price * state.arr[index].n
    // },
    // danxuan(state, index) {
    //   state.arr[index].checked = !state.arr[index].checked
    //   if (state.arr[index].checked == true) {
    //     state.he += state.arr[index].pricez*1
    //   }
    // }
    zhanghao(state, value) {
      state.value = value
    },
    mima(state, value1) {
      state.value1 = value1
    },
    arr(state, arr) {
      state.arrNew = arr
    },
    setN() {
      this.state.n++
    },
    tiaozhuan(arrNew2) {
      state.arrNew1.push(arrNew2)
    }
  },
  modules: {
    meituan,
  },
  getters: {

  },
  actions: {
    actionsSetN(state) {
      setTimeout(() => {
        var n = 0
        state.commit("setN")
      }, 0);
    }
    // setN(){
    //   this.$store.dispatch("actionSetN")
    // }
  },
  plugins: [vuexLocal.plugin],

})
